package com.zhaoxi.project.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.wms.domain.WmsOrder;
import com.zhaoxi.project.wms.service.impl.WmsOrderServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.web.page.TableDataInfo;

/**
 * 跟物品有关的订单Controller
 *
 * @author zhaoxi
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/wms/order")
public class WmsOrderController extends BaseController {
    @Autowired
    private WmsOrderServiceImpl wmsOrderService;

    /**
     * 查询跟物品有关的订单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsOrder wmsOrder) {
        startPage();
        List<WmsOrder> list = wmsOrderService.selectWmsOrderList(wmsOrder);
        return getDataTable(list);
    }

    /**
     * 导出跟物品有关的订单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:order:export')")
    @Log(title = "跟物品有关的订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsOrder wmsOrder) {
        List<WmsOrder> list = wmsOrderService.selectWmsOrderList(wmsOrder);
        ExcelUtil<WmsOrder> util = new ExcelUtil<WmsOrder>(WmsOrder.class);
        util.exportExcel(response, list, "跟物品有关的订单数据");
    }

    /**
     * 获取跟物品有关的订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wmsOrderService.selectWmsOrderById(id));
    }

    /**
     * 新增跟物品有关的订单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:add')")
    @Log(title = "跟物品有关的订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsOrder wmsOrder) {
        return toAjax(wmsOrderService.insertWmsOrder(wmsOrder));
    }

    /**
     * 修改跟物品有关的订单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:edit')")
    @Log(title = "跟物品有关的订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsOrder wmsOrder) {
        return toAjax(wmsOrderService.updateWmsOrder(wmsOrder));
    }

    /**
     * 删除跟物品有关的订单
     */
    @PreAuthorize("@ss.hasPermi('wms:order:remove')")
    @Log(title = "跟物品有关的订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wmsOrderService.deleteWmsOrderByIds(ids));
    }


    /**
     * 获取跟物品有关的订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:order:query')")
    @GetMapping(value = "/line/{id}")
    public AjaxResult getOrderLine(@PathVariable("id") Long id) {
        return success(wmsOrderService.getOrderLine(id));
    }
}